package com.example.team6.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.team6.entity.Student;
import com.example.team6.entity.Work;
import com.example.team6.entity.resultt;
import com.example.team6.mapper.WorkMapper;
import com.example.team6.service.WorkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author team6
 * @since 2020-06-28
 */
@RestController
@CrossOrigin
//@RequestMapping("/team6/work")
public class WorkController {
    @Autowired
    WorkService workService;
    @Autowired
    WorkMapper workMapper;

    @PostMapping(value = "api/stuwork")
    @ResponseBody
    public List<Work> stuwork (@RequestBody Work requestUser){

        System.out.println(requestUser.getWorkid());

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("courseid", requestUser.getCourseid());


        List<Work> workList = workMapper.selectByMap(map);
        //List<Work> workList = workMapper.selectList(null);

        return workList;
    }

    @PostMapping(value = "api/stuworkbyid")
    @ResponseBody
    public List<Work> stuworkbyid (@RequestBody Work requestUser){

        System.out.println(requestUser.getWorkid());

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("workid", requestUser.getWorkid());


        List<Work> workList = workMapper.selectByMap(map);
        //List<Work> workList = workMapper.selectList(null);

        return workList;
    }


    @PostMapping(value = "api/teacher/work")
    @ResponseBody
    public resultt upwork (@RequestBody Work requestUser){

        resultt resultt = new resultt();

        Work work =new Work();

        work.setCoursename(requestUser.getCoursename());
        work.setEndtime(requestUser.getEndtime());
        work.setFirsttime(requestUser.getFirsttime());
        work.setWorktext(requestUser.getWorktext());
        work.setCourseid(requestUser.getCourseid());
        work.setUrl(requestUser.getUrl());
      //  work.setTeacherid(requestUser.getTeacherid());

        Integer result = workMapper.insert(work);

        if (null == result) {
            String massage = "账号密码错误";
            return new resultt(400);
        } else {
            System.out.println("test");
            Map<String, Object> map = new HashMap<String, Object>();
            resultt.setCode(200);
            map.put("workid", work.getWorkid());
            resultt.setData(map);
        }
        return resultt;
    }


}

